package com.wujie.market.controller;

import com.wujie.market.po.User;
import com.wujie.market.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * ClassName: UserController
 * Description:
 * date: 2023/2/22 20:53
 *
 * @author 吴杰
 * @since JDK 1.8.0_31
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/login")
    public Map<String,Object> login(@RequestBody User user){
        Map<String,Object> map=new HashMap<>();
        User resultUser = userService.queryPassword(user.getUsername());
        if(resultUser==null){
            map.put("code",400);
            map.put("msg","用户名不存在，请注册");
        }
        if (!user.getPassword().equals(resultUser.getPassword())){

            map.put("msg","登录失败,用户名或密码错误");
            map.put("code",400);
            return map;
        }
        map.put("msg","登录成功");
        map.put("code",200);
        map.put("userId",resultUser.getUsername());
        return map;
    }
}
